<div class="popup_content_box" style="padding-left: 15px;height: 60%;overflow-y: auto;overflow-x: hidden;" >
    <{if $rolls|count gt 0}>
        <{foreach from=$rolls item=item key=key}>
        <input type = "hidden" id = "productId" value = "<{$item[0][0]['productId']}>" name = "productId">
        <div style="text-align: center;border-bottom: 2px solid #efefef;font-size: 14px;font-weight: bold;"><span style="display: inline-block;background-color: #efefef;width: 130px;"><{t}>批号<{/t}>：<{$item.num}></span></div>
            <{foreach from=$item item=_item key=aaa}>
                <div style="width: 300px;">
                    <{foreach from=$_item item=it}>
                        <{if $it['id'] > 0}>
                            <div style="float: left;width: 30%;margin: 5px 5px 5px 5px">
                                <input type="checkbox" name="chkRoll[]" value='<{$it['id']}>' cnt='<{$it['cntMi']}>' id="chkRoll[<{$it['id']}>]" class="chkRoll" >
                                <label for="chkRoll[<{$it['id']}>]" ><{$it['rollNo']}>#-<{$it['cnt']}><{$it['unit']}>
                                </label>
                            </div>
                        <{/if}>
                    <{/foreach}>
                </div>
            <{/foreach}>
        <div style="clear: both;"></div>
        <{/foreach}>
        <table class="table-peihuo">
            <tr>
                <th colspan="2" style="width: 30%">
                <li class ='product-buy-quantity'>数量(M)：<input type='text' id = 'cntM'><a href="javascript:autoPeihuo();" class="btn-peihuo">自动配货</a>
                </li>
                </th>
            </tr>
            <tr>
                <th colspan="2">
                <button type="button" class="btn-caution btnSure">确认配货</button>
                </th>
            </tr>
        </table>
    <{else}>
        <label><b style='font-size:15px;'><{t}>未发现码单信息！请重新选择<{/t}></b></label>
    <{/if}>
    <span id='divTotal'></span>
</div>
<div style="position: relative;width: 1.8rem;top: 105px;right: 19px;float: right;">
    <{img src="images/icon_close.png" class="icon_close" app='wap'}>
</div>
<script type="text/javascript">
    //每次选中，会重新计算总卷数和总米数
    //1Y = 0.9144M,ec端只考虑米数
    $$('.chkRoll').addEvent('click',function(e){
        var sign = 0;
        var totalCnt=0;
        var cnt=0;
        var ids= [];
        var cntM = [];
        var inputs = document.getElementsByName('chkRoll[]');//获取所有的input标签对象。
        for(var i=0;i<inputs.length;i++){
        var obj = inputs[i];
            if(obj.type=='checkbox'){
                if(obj.checked==true){
                    sign++;
                    id = obj.value;
                    cnt = parseFloat(obj.getAttribute("cnt"))||0;
                    totalCnt=parseFloat(totalCnt)+cnt;
                    totalCnt=totalCnt.toFixed(3);
                    cntM.push(cnt);
                    ids.push(id);
                }
            }
        }
        totalCnt=parseFloat(totalCnt).toFixed(2);
        //往选中之中填值
        //合计显示在页面上
        var totalStr="<b>选中:"+"<font color='red'>"+sign+"</font>&nbsp;&nbsp;卷&nbsp;&nbsp;共:"+"<font color='red'>"+totalCnt+"</font>&nbsp;&nbsp;M</b> <div type='hidden' id='total' value='"+totalCnt+"' cntJuan='"+sign+"' madan_ids='"+ids+"' cntM='"+cntM+"'></div> ";
        var spanDiv=window.document.getElementById ("divTotal");
        spanDiv.innerHTML = totalStr;
    });

    //2015-9-11 by jeff确认后,ajax访问后台，修改购物车数据后，动态改变当前页面的相关数据
    //包括数量和卷数
    $$('.btnSure').addEvent('click',function(e){
        $('.content').css({
        　　"overflow-x":"hidden",
        　　"overflow-y":"auto"
        });
        var inputCnt = $$('[name="goods[num]"]');
        var inputIds = $$('[name="goods[madan_ids]"]');
        var inputJu = $$('[name="goods[juanshu]"]');
        var inputCntm = $$('[name="goods[cntM]"]');
        inputCnt.set('value',window.document.getElementById("total").getAttribute('value'));
        inputIds.set('value',window.document.getElementById("total").getAttribute('madan_ids'));
        inputJu.set('value',window.document.getElementById("total").getAttribute('cntJuan'));
        inputCntm.set('value',window.document.getElementById("total").getAttribute('cntM'));
        $$('#peihuo-pop').hide();
        // alert('ajax访问后台，修改购物车数据后，刷新当前页面或者动态改变当前页面的某些区域的数据');

    });

    /**
     * ps ：自动配货
     * Time：2015/10/26 20:23:23
     * @author liuxin
     * @param 参数类型
     * @return 返回值类型
    */
    function autoPeihuo(){
        var inputs = document.getElementsByName('chkRoll[]');//获取所有的input标签对象。
        for(var i=0;i<inputs.length;i++){
        var obj = inputs[i];
            if(obj.type=='checkbox'){
                if(obj.checked==true){
                    obj.checked = false;
                }
            }
        }
        var id = document.getElementById("productId").value;
        var cntM = document.getElementById("cntM").value;
        if(isNaN(Number(cntM))||cntM == ''||cntM <= 0){
            document.getElementById("cntM").value = "0";
            var totalStr="<b><{t}>选中<{/t}>:"+"<font color='red'>"+"0"+"</font>&nbsp;&nbsp;<{t}>卷<{/t}>&nbsp;&nbsp;<{t}>共<{/t}>:"+"<font color='red'>"+"0"+"</font>&nbsp;&nbsp;M</b> <div type='hidden' id='total' value='"+"0"+"' cntJuan='"+"0"+"' madan_ids='"+""+"'></div> ";
            var spanDiv=window.document.getElementById ("divTotal");
            spanDiv.innerHTML = totalStr;
            return;
        }
        var url = "<{link app=b2c ctl=wap_order act=autoPeihuo}>";
        new Request({
            method: 'post',
            url:url,
            data:{'product_id':id,'cntM':cntM},
            onSuccess:function(rs){
                try{
                        rs = JSON.decode(rs);
                        if(rs.error) {
                            return Message.error(rs.error);
                        }
                    }catch(e) {
                        updateBasic(rs, id, url,atext);
                    }
                if(rs.data.length==0){
                    alert("<{t}>配货失败,请检查填入数量是否正确！<{/t}>");
                    return;
                }

                for(var i=0;i<rs.data.length;i++){
                    $$("[id='chkRoll["+rs.data[i]+"]']").set('checked','checked');
                }

                var sign = 0;
                var totalCnt=0;
                var cnt=0;
                var ids= [];
                var cntM = [];
                for(var i=0;i<inputs.length;i++){
                var obj = inputs[i];
                    if(obj.type=='checkbox'){
                        if(obj.checked==true){
                            sign++;
                            id = obj.value;
                            cnt = parseFloat(obj.getAttribute("cnt"))||0;
                            totalCnt=parseFloat(totalCnt)+cnt;
                            totalCnt=totalCnt.toFixed(3);
                            ids.push(id);
                            cntM.push(cnt);
                        }
                    }
                }
                totalCnt=parseFloat(totalCnt).toFixed(2);
                // if(cntM>totalCnt){
                //     alert("输入数量大于库存，已为您选择最大库存数量！");
                // }
                document.getElementById("cntM").value = totalCnt;
                //往选中之中填值
                //合计显示在页面上
                var totalStr="<b><{t}>选中<{/t}>:"+"<font color='red'>"+sign+"</font>&nbsp;&nbsp;<{t}>卷<{/t}>&nbsp;&nbsp;<{t}>共<{/t}>:"+"<font color='red'>"+totalCnt+"</font>&nbsp;&nbsp;M</b> <div type='hidden' id='total' value='"+totalCnt+"' cntJuan='"+sign+"' madan_ids='"+ids+"' cntM='"+cntM+"'></div> ";
                var spanDiv=window.document.getElementById ("divTotal");
                spanDiv.innerHTML = totalStr;
            }
        }).post();
    }
    $(".icon_close") .click(function(){
        // $$('#peihuo-pop').hide();
        $("#peihuo-pop").css('display','none');
        $('.content').css({
        　　"overflow-x":"hidden",
        　　"overflow-y":"auto"
        });
    })
</script>